package com.yanqu.road.server.cmd.inn;

import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.pb.inn.InnProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.inn.InnModule;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_INN_DISHES_UPGRADE, desc = "菜品技能升级")
public class InnDishesUpgradeCmd extends AbstractCommand {

    private int dishesId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {

        InnProto.InnDishesUpgradeReqMsg reqMsg = InnProto.InnDishesUpgradeReqMsg.parseFrom(packet.getBytes());
        dishesId = reqMsg.getDishesId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (!SystemOpenMgr.systemOpen(player, eSystemId.Inn.getValue())) {
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }

        InnModule module = player.getModule(InnModule.class);
        ret = module.dishesUpgrade(dishesId);
    }

    @Override
    public void sendData(GamePlayer player) {
        InnProto.InnDishesUpgradeRspMsg.Builder respMsg = InnProto.InnDishesUpgradeRspMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(Protocol.U_INN_DISHES_UPGRADE, respMsg);
    }
}
